<?php
/**
 * Add a partner to a mission
 * 
 */

use Hive\Mission\Partner;
use Hive\Mission;

$xview = Xview::instance();
$missionid = $xview->val("missionid");

$block = $xview->component("missions","ressources");
$grid = $block->item("gRessources");

try {
	$mission = new Mission($missionid);
	$mission->partners();
	// Posted date
	$codes = Xview::instance()->val("codes");

	if(!empty($codes) && count($codes) > 0)
	{
		foreach($codes as $partnerid)
		{
			$mission->partner($partnerid,Partner::ROLE_CANDIDATE);
		}
	}
	$mission->prepareUpdate(Mission::CHANGE_PARTNERS);
	$mission->update();
	$customers = $mission->partnersSourceObjects();
	$grid->setDatas($customers);
}
catch (Fox\Object\Exception\NotExist $e)
{
	
}
echo $block->display();